/* Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
 * All rights reserved.
 *
 * This software is supplied "AS IS" without any warranties.
 * RDA assumes no responsibility or liability for the use of the software,
 * conveys no license or title under any patent, copyright, or mask work
 * right to the product. RDA reserves the right to make changes in the
 * software without notification.  RDA also make no representation or
 * warranty that such application will be suitable for the specified use
 * without further testing or modification.
 */

#ifndef _DRV_TP_H_
#define _DRV_TP_H_

#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include <drv_gpio.h>
OSI_EXTERN_C_BEGIN

#define TP_SCAN_FILTER_NUM          4
#define FILTER_ABANDON_NUM          1


typedef enum {
    TP_ADC_RANGE_1V250 = 0,
    TP_ADC_RANGE_2V444 = 1,
    TP_ADC_RANGE_3V233 = 2,
    TP_ADC_RANGE_5V000 = 3,
    TP_ADC_RANGE_MAX   = 3,
} tp_adc_scale_t;

typedef enum {
    TP_TOUCH_EVENT_none = 0,
    TP_TOUCH_EVENT_press,
    TP_TOUCH_EVENT_shortPress,
    TP_TOUCH_EVENT_longPress,
    TP_TOUCH_EVENT_shortRelease,
    TP_TOUCH_EVENT_longRelease,
} tp_touch_event_t;

typedef enum {
    TP_CALIB_PHASE_wait_1st,
    TP_CALIB_PHASE_wait_2nd,
    TP_CALIB_PHASE_wait_3th,
    TP_CALIB_PHASE_done,
} tp_calib_phase_t;

typedef struct
{
    int32_t x;
    int32_t y;
} tp_point_t;

typedef struct {
    // ADC index
    uint8_t x_adc;
    uint8_t y_adc;
    
    // pin index
    uint16_t xp_pin;
    uint16_t xn_pin;
    uint16_t yp_pin;
    uint16_t yn_pin;
} tp_cfg_t;

typedef struct {
    tp_touch_event_t event;
    tp_point_t coord;
} tp_result_t;

typedef struct {

    // ADC maximum vaule of valid touch
    uint32_t max_valid_val;

    int32_t (*init)(tp_cfg_t tp_cfg);
    int32_t (*getXAdcVal)(void);
    int32_t (*getYAdcVal)(void);
    int32_t (*deinit)(void);
} tp_dev_t;

/**
 * @brief TP tcouch callback
 * 
 */
typedef void (*tp_touch_cb_t)(tp_result_t);

/**
 * @brief TP calibration callback
 * 
 */
typedef void (*tp_calib_cb_t)(tp_calib_phase_t);

OSI_EXTERN_C_END

#endif
